<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>promis编程模型</h1>
	</body>
	
	<script>
		
		demo02();
		 
		 
		 function demo01(){
			 
			 var keepsHisWord=false; 
			promise1 = new Promise(function(resolve, reject) {
			  if (keepsHisWord) {
				resolve("小智承诺坚持分享好的东西给大家");
			  } else {
				reject("我没有做到！");
			  }
			});
			
			console.log(promise1);
		 
		 }
		 
		 function demo02(){
			 
			 //异步模型
			 promise2 = new Promise(function(resolve, reject) {
			   setTimeout(function() {
			     resolve({
			       message: "小智承诺坚持分享好的东西给大家",
			       code: "200"
			     });
			   }, 5 * 1000);
			 });
			 
			 //你按照承诺执行
			promise2.then(function(resp){
				console.log("promise模型，resolve通过了-返回结果");
				console.log(resp);
			})
			 
			 //没有按照承诺执行
			 promise2.catch(function(resp){
			 	console.log("promise模型，reject通过了-返回结果");
			 	console.log(resp);
			 })
			 
			 //不管承诺成功还是失败，最终还是加来
			 promise2.finally(function(){
			 	console.log("promise模型，finally --整个异步模型执行完成"); 
			 })
		 }
		
	</script>
</html>
